package com.youlu.campus.web.commission;

import com.youlu.campus.entity.UserPO;
import com.youlu.campus.entity.commission.dto.DistributorAccountBindAccountDTO;
import com.youlu.campus.entity.commission.dto.DistributorAccountWithdrawDTO;
import com.youlu.campus.entity.commission.dto.DistributorAccountWithdrawQuery;
import com.youlu.campus.service.commission.DistributorAccountService;
import com.youlu.campus.web.common.base.RequestContext;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : [dengbo]
 * @className : DistributorAccountController
 * @description : [账户信息]
 * @createTime : [2023/2/6 14:25]
 */
@Slf4j
@RestController
@RequestMapping("/mini-app/")
public class DistributorAccountController {
    @Autowired
    private DistributorAccountService distributorAccountService;

    /**
     * 查询分拥账户信息
     * 参数：request - 获取账户信息
     */
    @PostMapping("/distributor/account/info")
    public QResult getAccountInfo() {
        return QResult.success(distributorAccountService.getAccountInfo(RequestContext.getUserId()));
    }

    /**
     * 分拥提现列表
     * 备注：提现列表
     * 参数：request - 提现列表
     */
    @PostMapping("/distributor/account/withdraw/list")
    public QResult getWithdrawList(@RequestBody @Validated DistributorAccountWithdrawQuery query) {
        query.setAccountId(RequestContext.getUserId());
        return QResult.success(distributorAccountService.getWithdrawList(query));
    }

    /**
     * 分拥提现
     * 备注：用户提现
     * 参数：request - 用户提现
     */
    @PostMapping("/distributor/account/user/withdraw")
    public QResult distributorWithdraw(@RequestBody @Validated DistributorAccountWithdrawDTO query) {
        UserPO userPO = RequestContext.getCurUser();
        query.setOpenId(userPO.getOpenId());
        query.setUserId(RequestContext.getUserId());
        query.setAppId(RequestContext.getAppId());
        query.setUserPO(RequestContext.getCurUser());
        query.setType(0);
        return QResult.success(distributorAccountService.distributorWithdraw(query));
    }

    /**
     * 绑定支付账户
     * 备注：用户提现
     * 参数：request - 绑定账户
     */
    @PostMapping("/distributor/account/bind/pay/account")
    public QResult bindAccount(@RequestBody @Validated DistributorAccountBindAccountDTO query) {
        query.setUserId(RequestContext.getUserId());
        return QResult.success(distributorAccountService.bindAlipay(query));
    }
}